package com.xpffly.design.iterator.common;

import com.xpffly.design.iterator.common.service.Aggregate;
import com.xpffly.design.iterator.common.service.Iterator;
import com.xpffly.design.iterator.common.service.impl.ConcreteAggregate;

/**
 * @Author: xpengfei
 * @Date: 2021/4/13 20:38
 * @Description：迭代器模式通用代码场景类
 */
public class Scene {
    public static void main(String[] args) {
        // 声明出容器
        Aggregate aggregate = new ConcreteAggregate();
        aggregate.add("abc");
        aggregate.add("123");
        aggregate.add("456");
        aggregate.add("789");
        // 遍历
        Iterator iterator = aggregate.iterator();
        // 这里的迭代有问题，会死循环，书中代码有误
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }
}
